Skip to content

MCP enhancements: improves server config and adds support for all transport types (stdio, streamable-http) #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 38 commits into
base: develop
Choose a base branch
from

Conversation

AnuradhaKaruppiah
Copy link
Contributor

@AnuradhaKaruppiah AnuradhaKaruppiah commented May 21, 2025

Description

Closes #304, #314

This PR

  1. Allows MCP servers to be configured without wrapping each tool on the server as a separate static function. It does that by introducing a new mcp_client function. This function connects to the server, discovers tools and adds them as dynamic functions (mcp_single_tool) to the AIQ workflow builder.
  2. Adds support for local MCP services using stdio

Sample usage (see examples/simple_calculator/configs/config-mcp-date-stdio.yml) -

functions:
  mcp_time:
    _type: mcp_client
    server:
      transport: stdio
      command: "python"
      args: ["-m", "mcp_server_time", "--local-timezone=America/Los_Angeles"]
    # load 1 of 2 tools and override tool attributes
    tool_filter:
      get_current_time:
        alias: get_current_time_mcp_tool
        description: "Returns the current date and time from the MCP server"

  mcp_math:
    _type: mcp_client
    server:
      transport: sse
      url: "http://localhost:9901/sse"
    # load all tools and use the names and descriptions from the server

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

@AnuradhaKaruppiah AnuradhaKaruppiah self-assigned this May 21, 2025
@AnuradhaKaruppiah AnuradhaKaruppiah added improvement Improvement to existing functionality non-breaking Non-breaking change labels May 21, 2025
@AnuradhaKaruppiah AnuradhaKaruppiah marked this pull request as draft May 21, 2025 01:53
@AnuradhaKaruppiah AnuradhaKaruppiah marked this pull request as ready for review May 22, 2025 18:26
@AnuradhaKaruppiah AnuradhaKaruppiah requested a review from Copilot May 22, 2025 19:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the MCP tool wrapper to support stdio mode in addition to the existing SSE mode. Key changes include:

  • Updating the MCPToolConfig schema and client builder to support stdio parameters (command, args, env).
  • Refactoring the MCP client structure by introducing a base client and a dedicated MCPStdioClient.
  • Enhancing CLI commands, tests, and documentation to demonstrate and verify the stdio mode usage.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/aiq/tools/test_mcp.py Added tests for both SSE and stdio client usage, and for the MCPBuilder functionality.
src/aiq/tool/mcp/mcp_tool.py Updated configuration handling to support stdio mode with new parameters and validation.
src/aiq/tool/mcp/mcp_client.py Refactored client architecture by introducing a base client and a dedicated MCPStdioClient, and updated MCPBuilder accordingly.
src/aiq/cli/commands/info/list_mcp.py Enhanced CLI options to support stdio mode configuration including command, args, and environment variables.
examples/simple_calculator/src/aiq_simple_calculator/configs/config-mcp-date-stdio.yml Added sample config demonstrating usage of MCP stdio mode.
docs/source/workflows/mcp/mcp-client.md Updated documentation to include examples and explanation for both SSE and stdio mode configurations.

Copy link
Collaborator

@mdemoret-nv mdemoret-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could improve design a bit now that we have two client types by removing MCPBuilder

@AnuradhaKaruppiah AnuradhaKaruppiah force-pushed the ak-mcp-tool-stdio branch 2 times, most recently from 0eea228 to 22f704a Compare May 22, 2025 21:34
AnuradhaKaruppiah and others added 18 commits May 27, 2025 21:18
Sample Usage:
aiq info mcp --client-type stdio --command python --args "-m mcp_server_time --local-timezone=America/Los_Angeles"

Sample Output:
get_current_time
convert_time

Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
@AnuradhaKaruppiah AnuradhaKaruppiah marked this pull request as draft June 2, 2025 16:56
Signed-off-by: Anuradha Karuppiah <[email protected]>
Start of dynamic_functions

Signed-off-by: Anuradha Karuppiah <[email protected]>
@AnuradhaKaruppiah AnuradhaKaruppiah force-pushed the ak-mcp-tool-stdio branch 4 times, most recently from 30755ab to 98963be Compare June 4, 2025 23:05
This will need some iterating

Signed-off-by: Anuradha Karuppiah <[email protected]>
@AnuradhaKaruppiah AnuradhaKaruppiah changed the title Extend the MCP tool wrapper to work with stdio MCP enhancements: improves server config and adds support for all transport types (stdio, streamable-http) Jun 5, 2025
If no default is defined in the schema, and the field isn’t in
the "required" list, it should default to None (i.e., optional).

Earlier logic marked the field as required (using ...) unless
"default" is explicitly set i.e. it would mark optional fields
with no default as required.

Signed-off-by: Anuradha Karuppiah <[email protected]>
Signed-off-by: Anuradha Karuppiah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement to existing functionality non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA]: Add support for stdio MCP Servers
2 participants